package com.serene.authority.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.serene.authority.admin.entity.vo.MenuVo;
import com.serene.authority.admin.entity.vo.MenuIndexVo;
import com.serene.authority.admin.entity.MyMenu;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author serene
 * @createTime 2020/7/10
 */

@SuppressWarnings("ALL")
@Mapper
public interface MenuMapper extends BaseMapper<MyMenu> {

    /**
     * 模糊查询菜单
     *
     * @param queryName 查询的表题
     * @param queryType 查询类型
     * @return
     */
    @SuppressWarnings("AlibabaAbstractMethodOrInterfaceMethodMustUseJavadoc")
    List<MyMenu> getFuzzyMenu(String queryName, Integer queryType);

    /**
     * 菜单树
     *
     * @return
     */
    @Select("select m.menu_id,m.parent_id,m.menu_name from my_menu m")
    @Result(property = "title", column = "menu_name")
    @Result(property = "id", column = "menu_id")
    List<MenuVo> buildAll();

    /**
     * 更新菜单
     *
     * @param menu
     * @return
     */
    int update(MyMenu menu);

    /**
     * 通过父节点返回字节点
     *
     * @param parentId
     * @return
     */
    @Select("select m.menu_id from my_menu m where parent_id = #{parentId}")
    List<Integer> selectByParentId(Integer parentId);

    /**
     * 通过角色id返回菜单
     *
     * @param roleId
     * @return
     */
    @Select("select m.menu_id,m.parent_id,m.menu_name from my_menu m inner join my_role_menu rm on m.menu_id = rm.menu_id where rm.role_id = #{roleId}")
    @Result(property = "title", column = "menu_name")
    @Result(property = "id", column = "menu_id")
    List<MenuVo> listByRoleId(Integer roleId);

    /**
     * 通过用户id返回菜单
     *
     * @param userId
     * @return
     */
    List<MenuIndexVo> listByUserId(@Param("userId") Integer userId);
}
